<?php 
//require("../common/global.php");
require("../common/pdata_mysql.php");?>
<?php
	function disList($pid,$iname,$ptid,$frm,$coststat,$costdyn,$phase)
	{
		$sql = "select pid,iname,phid,ptid,frm,coststat,costdyn from itemdetail ".$check." order by ptid";

		echo "<ul>";
		$rs = mysql_query($sql,$conn) or die(mysql_error());
		
		switch ($phase)
		{
			case 1:
			case 2:
			case 3:
			case 4:
			default: break;
		}
		
		
		while($row = mysql_fetch_array($rs))
		{
			if((intval($row['phid']==1)||intval($row['phid']==2))&&$phase==1) 
			{	
			echo "<li>依据：".$row['frm']."</li>";
			echo "<li class='lstItem'>".$iname;
			
			echo "<span class='txtR'><span class='txtL'>静态投资".round($coststat)."万元</span><span class='txtL'>动态投资".round($costdyn)."万元</span></span>";
			echo "</li>";
			}
		}
		echo "</ul>";

	
	}
	
	
	function lsItem($iname,$coststat,$costdyn,$frm,$itemid)
	{
		echo "<li class='lstItem'><a target='_new' href='../item/item_view.php?itemid=".$itemid."'>".$iname."</a>";
		echo "<span class='txtR'>";
		echo "<span class='txtLLong'>来源:".$frm."</span>";
		echo "<span class='txtL'>静态投资:".round($coststat)."万元</span>";
		echo "<span class='txtL'>动态投资:".round($costdyn)."万元</span>";
		echo "</span>";
		echo "</li>";
	}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>工程管理</title>
<style type="text/css">
#stCheck {
	float: left;
	width: 960px;
}
#stDisplay {
	background-color: #9CF;
	float: left;
	width: 400px;
}
#stItem {
	float: left;
	width: 560px;
	background-color: #6CF;
}
.stInfo {
	padding: 0px;
	width: 400px;
}
.lstItem {
	float: left;
	width: 100%;
}
.txtR {
	float: right;
	font-size: 10px;
	color: #666;
}
.txtL {
	float: left;
	width: 120px;
}
.txtLLong {
	float: left;
	width: 240px;
}
.draftlist { clear: both; }
</style>
<link rel="stylesheet" type="text/css" href="/css/allstyle.css"/>
</head>

<body>
<div id="header">
  <?php include("../common/header.php") ?>
</div>
<div id="wrap">
  <div id="top"><a href="/job/project/pro_list.php">全部工程列表</a> | <a href="/job/project/pro_insert.php">新增工程数据</a></div>
  <div id="stCheck">
    <form>
      <label for="pj">建设工程关键字查询</label>
      <input type="text" name="pj" />
      <input type="submit" />
    <?php 
	if(isset($_GET['pj']))
		{$pj = $_GET['pj'];
		$sql = "SELECT pid,projectname,oldname,donedraft FROM project WHERE projectname LIKE '%".$pj."%' OR oldname LIKE '%".$pj."%' ORDER BY pid";
		$conn = mysql_pconnect($hostname_pdata,$username_pdata,$password_pdata);
		mysql_select_db("pdata");
		$rs = mysql_query($sql,$conn) or die(mysql_error());
		while($row = mysql_fetch_array($rs))
		{
			echo "<div>";
			echo "<a href='?pid=".$row['pid']."&pj=".$pj."#info'>工程名称：".$row['projectname'];
			if($row['oldname']) 
				echo " | 曾用名称：".$row['oldname'];
			echo "</a>";
			echo "</div>";
		}
		mysql_close($conn);

		}
	else
		echo "没有查询到，请重新输入要查询输变电工程关键字。";
	?>
   </form>

  </div>
  <div id="stDisplay">
    <p><a name="info" id="info"></a>变电站站信息</p>
    <table cellpadding="0" class="stInfo">
      <tr>
        <td width='95px'>项目名称</td>
        <td>内容</td>
      </tr>
      <?php 
/////////////////////////////////
//按照stid的要求显示全部的变电站数据//
//或者只是部分的显示变电站的数据等等///
////////////////////////////////

$conn = mysql_pconnect($hostname_pdata,$username_pdata,$password_pdata);

if(isset($_GET['pid']))
  {$check = " WHERE pid = ".$_GET['pid'];
  
	  //查询全部或者满足要求$check要求的数据列表
	  mysql_select_db($database_pdata);
	  $sql = "SELECT * FROM project".$check;
	  $rs = mysql_query($sql,$conn) or die(mysql_error());
	  
	  $maxi = mysql_num_fields($rs);
	  while($row = mysql_fetch_array($rs))
	  {
		  for($i=0;$i<$maxi;$i++)
		  {
			  $proper = mysql_fetch_field($rs,$i);
			  echo "<tr>";
			  if($proper->name == 'projectname')
			  {
				  echo "<td>".$proper->name."</td>";
				  echo "<td><a href='project.php?pid=".$row[0]."'>".$row[$i]."</a>";
				  echo "</td>";
			  }
			  else
			  {
				  echo "<td>".$proper->name."</td>";
				  echo "<td>".$row[$i]."</td>";
				  
			  }
			  echo "</tr>";
		  }
		  echo "<tr>";
		  echo "<td><a href=pro_insert_item.php?pid=".$row[0]."  target='new'>添加所属项目</a></td>";
		  echo "</tr>";
	  }
  }
else
  $check = "";
	
mysql_close($conn);
?>
    </table>
  </div>
  <div id="stItem">
    <p>工程及所属输变电工程信息</p>
    <ul>
      <?php 
	  $conn = mysql_pconnect($hostname_pdata,$username_pdata,$password_pdata);
	  mysql_select_db("pdata");
	  if(isset($_GET['pid']))
	  {	$check = " WHERE pid = ".$_GET['pid'];
		$sql = "select pid,iname,phid,ptid,frm,coststat,costdyn,itemid from itemdetail ".$check." order by ptid";
		
	  ?>
      <li class="draftlist">可研阶段</li>
      <ul>
        <?php
		$rs = mysql_query($sql,$conn) or die(mysql_error());
		while($row = mysql_fetch_array($rs))
		{
			if(intval($row['phid']==1)||intval($row['phid']==2)) 
			{	
				lsItem($row['iname'],$row['coststat'],$row['costdyn'],$row['frm'],$row['itemid']);
			}
		}
	  ?>
      </ul>
      <li class="draftlist">初设阶段</li>
      <ul>
        <?php
		$rs = mysql_query($sql,$conn) or die(mysql_error());
		while($row = mysql_fetch_array($rs))
		{
			if(intval($row['phid']==3)||intval($row['phid']==4)) 
			{	
				lsItem($row['iname'],$row['coststat'],$row['costdyn'],$row['frm'],$row['itemid']);
			}
		}
	  ?>
      </ul>
      <li class="draftlist">施设阶段</li>
      <ul>
        <?php
		$rs = mysql_query($sql,$conn) or die(mysql_error());
		while($row = mysql_fetch_array($rs))
		{
			if(intval($row['phid']==5)||intval($row['phid']==6)) 
			{	
				lsItem($row['iname'],$row['coststat'],$row['costdyn'],$row['frm'],$row['itemid']);
			}
		}
	  ?>
      </ul>
      <li class="draftlist">完工阶段</li>
      <ul>
        <?php
		$rs = mysql_query($sql,$conn) or die(mysql_error());
		while($row = mysql_fetch_array($rs))
		{
			if(intval($row['phid']==7)) 
			{	
				lsItem($row['iname'],$row['coststat'],$row['costdyn'],$row['frm']);
			}
		}
	  ?>
      </ul>
      <?php
  }
  ?>
    </ul>
  </div>
  <div class="clean"></div>
</div>

<div id="footer">
  <?php include("../common/footer.php") ?>
</div>
</body>
</html>